<template>
  <div class="board-view__card" @click="clickRsr(boardItem.id)">
    <div class="board-view__content">
      <div class="board-view__img">
        <svg-icon :iconclass="boardItem.url" v-if="isSvgFile(boardItem.url)"></svg-icon>
        <img :src="boardItem.img"></img>
      </div>
      <div class="board-view__info">
        <div class="board-view__title">
          <el-tooltip effect="dark" placement="bottom">
            <div slot="content">{{ boardItem.name }}</div>
            <span>
              {{ boardItem.segmentName }}
            </span>
          </el-tooltip>
        </div>
        <div class="board-view__views">
          <i class="el-icon-view"></i>
          {{ formatNumber(boardItem.clickNum) }}
        </div>
        <div class="board-view__description">
          {{ boardItem.note }}
        </div>
      </div>
    </div>
    <div class="board-view__tags">
      <el-tag effect="plain" type="info" v-for="(k, v) in dims.TAGS" v-if="parseTag(boardItem.tags, v)">
        {{ k }}
      </el-tag>
    </div>
  </div>
</template>

<script>
import slotFunc from '@/mixins/rsr-slot';
import textFunc from '@/mixins/text-line';
import tagFunc from '@/mixins/tag';
import numberFunc from '@/mixins/number';
export default {
  name: 'BoardView',
  mixins: [slotFunc, textFunc, tagFunc, numberFunc],
  props: {
    items: Object
  },
  data() {
    return {
      boardItem: null,
      // 字典
      dims: sa.$sys.getCurd(),
    }
  },
  watch: {
    items: {
      handler(newVal) {
        this.boardItem = newVal
      },
      deep: true
    }
  },
  created: function () {
    this.boardItem = this.items
  },
  methods: {
    // 判断是否是svg
    isSvgFile(param) {
      if (param) {
        return param.endsWith("svg") || param.endsWith("SVG")
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.board-view__card {
  display: flex;
  flex-direction: column;
  cursor: pointer;
  margin: 0 12px 12px 0;
  width: 280px;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid #f0f0f0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  min-height: 160px;
}

.board-view__card:hover {
  border-color: #e0e0e0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px) scale(1.02);
}

.board-view__content {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex: 1;
  margin-bottom: 12px;
  min-height: 80px;
}

.board-view__img {
  flex: 0 0 60px;
  position: relative;
  margin-top: 2px;
}

.board-view__img img {
  border-radius: 8px;
  width: 60px;
  height: 60px;
  object-fit: cover;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
  .board-view__img img {
    cursor: pointer;
  }
}

.board-view__info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  padding: 4px 0;
}

@media (max-width: 768px) {
  .board-view__card {
    width: 100%;
    margin: 0 0 16px 0;
    padding: 12px;
  }

  .board-view__content {
    gap: 16px;
    margin-bottom: 16px;
  }

  .board-view__img {
    flex: 0 0 72px;

    img {
      width: 72px;
      height: 72px;
    }
  }
}

@media (max-width: 480px) {
  .board-view__card {
    padding: 12px;
    min-height: auto;
  }

  .board-view__content {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
  }

  .board-view__info {
    width: 100%;
  }

  .board-view__img {
    flex: 0 0 80px;

    img {
      width: 80px;
      height: 80px;
    }
  }

  .board-view__title {
    font-size: 16px;
    margin-bottom: 6px;
  }

  .board-view__views {
    font-size: 13px;
  }

  .board-view__description {
    font-size: 13px;
    height: auto;
    margin-top: 6px;
  }
}

@media (max-width: 375px) {
  .board-view__card {
    padding: 10px;
  }

  .board-view__img {
    flex: 0 0 64px;

    img {
      width: 64px;
      height: 64px;
    }
  }

  .board-view__title {
    font-size: 15px;
  }

  .board-view__views {
    font-size: 12px;
  }

  .board-view__description {
    font-size: 12px;
  }
}

.board-view__title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  line-height: 1.4;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.board-view__views {
  font-size: 12px;
  color: #666;
  display: flex;
  align-items: center;

  i {
    margin-right: 4px;
    font-size: 14px;
  }
}

.board-view__description {
  font-size: 12px;
  color: #999;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
  height: 36px;
}

.board-view__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding-top: 8px;
  border-top: 1px solid #eee;

  .el-tag {
    margin: 0;
    font-size: 12px;
    padding: 0 6px;
    height: 22px;
    line-height: 22px;
  }
}
</style>
